import { defineStore } from 'pinia';
import { ref, computed } from 'vue';

export const usePublicStore = defineStore('public', () => {
	
	const app = getApp();
  
  const currentTab = ref(0);
  const userInfo = ref();
  
  const setUserInfo = (data :any) =>{
	  userInfo.value = data
  }
  const getUserInfo = () =>{
	  return userInfo.value
  }
  const updateUserInfo = () =>{
	  console.log("update")
	  const baseUrl = app.globalData.baseUrl;
	  uni.request({
	  	url: encodeURI(baseUrl + '/ygtUser/getUser'),
	  	method: 'GET',
	  	data: {
	  		"id":uni.getStorageSync("userId")
	  	},
	  	header: {
	  		"X-Tenant-Id": uni.getStorageSync("tenantId"),
			"token" : uni.getStorageSync("token")
	  	},
	  	success: (res) => {
	  		setUserInfo(res.data!.data)
			console.log(userInfo)
	  	}
	  });
  }
  
  const setCurrentTab =(num :number)=>{
	  currentTab.value = num;
  }
  const getCurrentTab = () =>{
	  return currentTab.value
  }
  
  return {
	  setUserInfo,
	  getUserInfo,
	  updateUserInfo,
    setCurrentTab,
	getCurrentTab
  };
});